#include "config_main.h"
#ifdef DDENN_INS_HSI
/*
 * ins_accelerometer_am9.cpp
 *
 *  Created on: 08.06.2009
 *      Author: Admin
 */
#include "ins_hsi.h"


bool isPushForHsiTest=0;
int isPushForHsiTestIndex=0;

void DdennHSI::RegisterDdennHSI(){
	  XPLMRegisterCommandHandler(XPLMCreateCommand(
              "ddenn/instruments/hsi/test",
              "PushForTest HSI") ,
              HSITest,1, NULL);
	  XPLMRegisterDataAccessor( "ddenn/instruments/hsi/cdi_horisontal" ,    xplmType_Float, 0,NULL,NULL,
			  GetInsHSICDIHorisontal, NULL,NULL, NULL,NULL,NULL,NULL,  NULL,NULL,    NULL,  NULL,NULL);

	  XPLMRegisterDataAccessor( "ddenn/instruments/hsi/cdi_vertical" ,    xplmType_Float, 0,NULL,NULL,
			  GetInsHSICDIVertical, NULL,NULL, NULL,NULL,NULL,NULL,  NULL,NULL,    NULL,  NULL,NULL);

	  XPLMRegisterDataAccessor( "ddenn/instruments/hsi/hdg_flag" ,    xplmType_Int, 0,
			  GetInsHSIHDGFlag,NULL,NULL, NULL,NULL, NULL,NULL,NULL,NULL,  NULL,NULL,    NULL,  NULL,NULL);

	  XPLMRegisterDataAccessor( "ddenn/instruments/hsi/nav_flag" ,    xplmType_Int, 0,
			  GetInsHSINAVFlag,NULL,NULL, NULL,NULL, NULL,NULL,NULL,NULL,  NULL,NULL,    NULL,  NULL,NULL);

	  XPLMRegisterDataAccessor( "ddenn/instruments/hsi/ils_flag" ,    xplmType_Int, 0,
			  GetInsHSIILSFlag,NULL,NULL, NULL,NULL, NULL,NULL,NULL,NULL,  NULL,NULL,    NULL,  NULL,NULL);

	  XPLMRegisterDataAccessor( "ddenn/instruments/hsi/to_from_flag" ,    xplmType_Int, 0,
			  GetInsHSIToFromFlag,NULL,NULL, NULL,NULL, NULL,NULL,NULL,NULL,  NULL,NULL,    NULL,  NULL,NULL);

}
void DdennHSI::UnregisterDdennHSI(){

	 XPLMUnregisterCommandHandler(XPLMFindCommand( "ddenn/instruments/hsi/test") ,
								  HSITest,1, NULL);
	 XPLMUnregisterDataAccessor( XPLMFindDataRef("ddenn/instruments/hsi/cdi_horisontal") );
	 XPLMUnregisterDataAccessor( XPLMFindDataRef("ddenn/instruments/hsi/cdi_vertical") );
	 XPLMUnregisterDataAccessor( XPLMFindDataRef("ddenn/instruments/hsi/hdg_flag") );
	 XPLMUnregisterDataAccessor( XPLMFindDataRef("ddenn/instruments/hsi/nav_flag") );
	 XPLMUnregisterDataAccessor( XPLMFindDataRef("ddenn/instruments/hsi/ils_flag") );
	 XPLMUnregisterDataAccessor( XPLMFindDataRef("ddenn/instruments/hsi/to_from_flag") );

}


void DdennHSI::OnCrash(){

}

int DdennHSI::HSITest(
                                   XPLMCommandRef       inCommand,
                                   XPLMCommandPhase     inPhase,
                                   void *               inRefcon)
{
	isPushForHsiTestIndex=0;
	isPushForHsiTest=0;
	return 0;
}









float DdennHSI::GetInsHSICDIHorisontal ( void *               inRefcon){
	if (isPushForHsiTest) {
		isPushForHsiTestIndex++;
		if  (isPushForHsiTestIndex>100){
			isPushForHsiTest=false;
			isPushForHsiTestIndex=0;
		}
		return 0;
	}else  return	GetDataRefF("sim/cockpit2/radios/indicators/nav1_hdef_dots_pilot");
}

float DdennHSI::GetInsHSICDIVertical ( void *               inRefcon){
	return GetDataRefF("sim/cockpit2/radios/indicators/nav1_vdef_dots_pilot");
}


int DdennHSI::GetInsHSIHDGFlag ( void *               inRefcon){
	if (IsMainPowerOn(1)){
		return 1;
	}else{
		return 0;
	}
}

int DdennHSI::GetInsHSINAVFlag ( void *               inRefcon){
	if (GetDataRefI("sim/cockpit2/radios/indicators/nav1_flag_from_to_pilot")){
		return 1;
	}else{
		return 0;
	}
}


int DdennHSI::GetInsHSIILSFlag ( void *               inRefcon){
	if (GetDataRefI("sim/cockpit/radios/nav1_vdef_dot float")){
		return 1;
	}else{
		return 0;
	}
}


int DdennHSI::GetInsHSIToFromFlag ( void *               inRefcon){
	return GetDataRefI("sim/cockpit2/radios/indicators/nav1_flag_from_to_pilot");
}






#endif
